<?php include '../public/header.php' ?>
<?php include '../public/header_index.php' ?>
<body class="laytp-container">
<div id="opt_nav">
</div>

<div class="layui-card" id="search-form">
    <div class="layui-card-body">
        <form class="layui-form" id="TableSearchFormId" lay-filter="TableSearchForm" onkeydown="keyTableSearch('TableSearchForm', 'datalist')">
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-md3">
                        <label class="layui-form-label">工程名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" placeholder="请输入" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-col-md3">
                        <div class="layui-form-item search-div">
                            <div class="layui-form-item layui-inline">
                                <button class="laytp-btn laytp-btn-md laytp-btn-primary" id="TableSearchButton" type="button"><i class="layui-icon layui-icon-search"></i>查询</button>
                                <button class="layui-btn layui-btn-primary" onclick="listTableReset()" id="TableSearchReset" type="reset" ><i class="layui-icon layui-icon-refresh"></i>重置</button>
<!--                                <div id="search_open" onclick="toggle_search()">-->
<!--                                    <i class="layui-icon layui-icon-down"></i>展开-->
<!--                                </div>-->
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<div class="layui-card" id="table-card">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-col-md12" id="table_list">
                <div class="layui-card-body">
                    <table id="datalist" lay-filter="datalist"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/html" id="test-dropdown-toolbar-barDemo">
    <div class="tab-list-authbut">
        <a href="javascript:;" class="bar_opt" onclick="auth_but_func_show('查看','{{d.LAY_TABLE_INDEX}}')">查看</a>
    </div>
</script>
<script type="text/html" id="toolbarDemo">
    <div class = "layui-btn-container">
    </div>
</script>
<script>


    var currButAuth, currTabData;
    layui.use(["laytp",'laypage','table','dropdown','form','soulTable'], function () {
        var laypage = layui.laypage, table = layui.table, dropdown = layui.dropdown, form = layui.form, soulTable = layui.soulTable;


        $('#TableSearchReset').click(function () {
            $('.xmselect_div>xm-select').find('.xm-label-block').css('display','none');
            $('.xmselect_div').append('<div class="xmselect_title">请选择</div>');
            searchTableFunc(form, table)
        });


        setSouTableExport('工程-销售方报表');
        var mytable = table.render({
            elem: "#datalist",id: "datalist"
            ,url: facade.url(ask_engin_gong_tai_list),where: {}, page: true, height: 'full-140'
            ,soulSort: TabInit.soulSort,method: TabInit.method, toolbar: TabInit.toolbar, overflow: TabInit.overflow
            ,defaultToolbar: TabInit.defaultToolbar,filter: TabInit.filter
            ,request: TabInit.request,response: TabInit.response,contextmenu:get_table_contextmenu(soulTable)
            ,text: TabInit.text,totalRow: true
            ,parseData: function (res) {
                currButAuth = res.data.butauth;
                tableButShow(currButAuth);

                render_from();
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.data.total,
                    "data": res.data.data.data
                };
            }
            , cols: [[
                {type:'numbers',title:'序号',totalRowText: '合计',fixed:'left'}
                ,{field:'enginname',title:'工程名称',merge:true}
                ,{field:'gonger',title:'销售方名称'}
                ,{field:'hougongzhifee',title:'累计支付销售方(元)',totalRow: true,templet: function(d){
                        if(d.hougongzhifee){
                            return '<span class="colorlan" onclick="openNavPage(\'付款明细\',\'hou_gongzhi/detail.php?status=1&enginid='+d.enginid+'&fuer='+encodeURI(d.gonger)+'\');">'+parseFormatNum(d.hougongzhifee)+'</span>';
                        }else{
                            return '';
                        }
                    }}
                ,{field:'piaoshoufee',title:'销售方进项票累计价税合计(元)',totalRow: true,templet: function(d){
                        if(d.piaoshoufee){
                            return '<span class="colorlan" onclick="openNavPage(\'进项票明细\',\'piao_shou/detail.php?status=1&enginid='+d.enginid+'&xiaoer='+encodeURI(d.gonger)+'\');">'+parseFormatNum(d.piaoshoufee)+'</span>';
                        }else{
                            return '';
                        }
                    }}
                ,{field:'piaoshouratefee',title:'销售方进项票累计票面税额(元)',totalRow: true,templet: function(d){
                        if(d.piaoshouratefee){
                            return '<span class="colorlan" onclick="openNavPage(\'进项票明细\',\'piao_shou/detail.php?status=1&enginid='+d.enginid+'&xiaoer='+encodeURI(d.name)+'\');">'+parseFormatNum(d.piaoshouratefee)+'</span>';
                        }else{
                            return '';
                        }
                    }}
                ,{field:'keqiancai',title:'销售方可签采购合同金额(元)',totalRow: true,templet: function(d){
                        return parseFormatNum(d.keqiancai);
                    }}
                ,{field:'yiqiancai',title:'销售方已签采购合同金额(元)',totalRow: true,templet: function(d){
                        if(d.yiqiancai){
                            return '<span class="colorlan" onclick="openNavPage(\'采购合同\',\'contract_cai/index.php?status=1&enginid='+d.enginid+'&gonger='+encodeURI(d.gonger)+'\');">'+parseFormatNum(d.yiqiancai)+'</span>';
                        }else{
                            return '';
                        }
                    }}
                ,{field:'shencai',title:'销售方审批中采购合同金额(元)',totalRow: true,templet: function(d){
                        if(d.shencai){
                            return '<span class="colorlan" onclick="openNavPage(\'采购合同\',\'contract_cai/index.php?status=0&enginid='+d.enginid+'&gonger='+encodeURI(d.gonger)+'\');">'+parseFormatNum(d.shencai)+'</span>';
                        }else{
                            return '';
                        }
                    }}
                ,{field:'daiqiancai',title:'销售方待签采购合同金额(元)',totalRow: true,templet: function(d){
                        if(d.daiqiancai > 0){
                            return '<span class="colorhong">'+d.daiqiancai+'</span>';
                        }else{
                            return '';
                        }
                    }}
                ,{field:'kedijin',title:'可抵扣进项票价税合计(元)',totalRow: true,templet: function(d){
                        return parseFormatNum(d.kedijin);
                    }}
                ,{field:'yidijin',title:'已抵扣进项票价税合计(元)',totalRow: true,templet: function(d){
                        if(d.yidijin){
                            return '<span class="colorlan" onclick="openNavPage(\'抵扣退税明细\',\'hou_gongshui/detail.php?status=1&enginid='+d.enginid+'&xiaoer='+encodeURI(d.gonger)+'\');">'+parseFormatNum(d.yidijin)+'</span>';
                        }else{
                            return '';
                        }
                    }}
                ,{field:'yidirate',title:'已抵扣退税(元)',totalRow: true,templet: function(d){
                        if(d.yidirate){
                            return '<span class="colorlan" onclick="openNavPage(\'抵扣退税明细\',\'hou_gongshui/detail.php?status=1&enginid='+d.enginid+'&xiaoer='+encodeURI(d.gonger)+'\');">'+parseFormatNum(d.yidirate)+'</span>';
                        }else{
                            return '';
                        }
                    }}
                ,{field:'shengdijin',title:'剩余可抵扣进项票价税合计(元)',totalRow: true,templet: function(d){
                        return parseFormatNum(d.shengdijin);
                    }}
                ,{field:'shengdijinshui',title:'剩余可抵扣进项税额(元)',totalRow: true,templet: function(d){
                        return parseFormatNum(d.shengdijinshui);
                    }}
            ]]
            , done: function (res) {
                soulTable.render(this);

                currTabData = res.data;
                $.each(currTabData, function(index,item){
                    var chk = $('tr[data-index=' + item.LAY_TABLE_INDEX + '] .tab-list-authbut');
                    for (var key in currButAuth) {
                        if(currButAuth[key].pagetype === 0 || currButAuth[key].pagetype === 1){
                            if(currTabData[index].status != 1){
                                continue;
                            }
                            chk.append(' <a ' +
                                'href="javascript:;" ' +
                                'class="bar_opt layui-hide" ' +
                                'lay-event="search" ' +
                                'data-butname="'+currButAuth[key].butname+'" ' +
                                'data-title="'+currButAuth[key].title+'" ' +
                                'onclick="auth_but_func_'+currButAuth[key].butname+'(\''+currButAuth[key].title+'\', '+index+')"' +
                                '>'+currButAuth[key].title+'' +
                                '</a>');
                        }
                    }
                });
                show_tab_but(currTabData);
            }
        });


        listTableSearch(form, table);
    });


    function auth_but_func_show(buttitle, index){
        var trData = currTabData[index];
        openPage('show.php?id='+trData.id);
    }
    function auth_but_func_add(){
        openPageEdit('add.php?close=1');
    }
    function auth_but_func_add_flow(){
        openPageEdit('flow_add.php?close=1');
    }
    function auth_but_func_edit(buttitle, index){
        var trData = currTabData[index];
        openPageEdit('edit.php?close=1&id='+trData.id);
    }
    function auth_but_func_delete(buttitle, index){
        var trData = currTabData[index];
        data_delete(ask_engin_del, {id:trData.id});
    }
    function auth_but_func_kaijun(buttitle, index){
        var trData = currTabData[index];
        openPageEdit('kaijun.php?id='+trData.id, '770px', '490px');
    }
    function auth_but_func_ting(buttitle, index){
        var trData = currTabData[index];
        openPageEdit('ting.php?id='+trData.id, '770px', '490px');
    }
    function auth_but_func_beian(buttitle, index){
        var trData = currTabData[index];
        openPageEdit('beian.php?id='+trData.id);
    }
    function auth_but_func_xian(buttitle, index){
        var trData = currTabData[index];
        openPageEdit('xian.php?id='+trData.id);
    }
    function auth_but_func_manage(buttitle, index){
        var trData = currTabData[index];
        openPageEdit('manage.php?id='+trData.id);
    }
    function auth_but_func_duty(buttitle, index){
        var trData = currTabData[index];
        openPageEdit('duty.php?id='+trData.id);
    }
    function auth_but_func_files(buttitle, index){
        var trData = currTabData[index];
        openPageEdit('files.php?id='+trData.id);
    }
    function auth_but_func_yu(buttitle){
        var checkStatus = layui.table.checkStatus('datalist').data;
        if(checkStatus.length != 1){
            facade.error(buttitle + "：请选择单条数据");return false;
        }

        var checkData = checkStatus[0];
        if(checkData.isturn != 1 || checkData.status != 1){
            facade.error(buttitle + "：选择的数据正在申请中，无法操作");return false;
        }
        openPageEdit('yu.php?close=1&id='+checkData.id);
    }

</script>
</body>
</html>
